﻿<common:LayoutAwarePage
    x:Name="pageRoot"
    x:Class="XnReader.WinRT.Index"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:XnReader.WinRT"
    xmlns:common="using:XnReader.WinRT.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Page.Resources>
        <!--
            此页所显示的分组项的集合，绑定到完整
            项列表的子集，因为无法虚拟化组中的项
        -->
        <CollectionViewSource
            x:Name="groupedItemsViewSource"
            Source="{Binding Groups}"
            IsSourceGrouped="true"
            ItemsPath="TopItems"/>
        <CollectionViewSource x:Name="cvs2" IsSourceGrouped="true" />
    </Page.Resources>
    <common:LayoutAwarePage.TopAppBar>
        <AppBar x:Name="barNav" Height="140" Background="#E5040404" >
            <local:Navigation x:Name="navTop" Margin="60,0,40,0" />
        </AppBar>
    </common:LayoutAwarePage.TopAppBar>
    <common:LayoutAwarePage.BottomAppBar>
        <AppBar Height="90" Background="#E5040404" >
            <local:ToolBar x:Name="tlBottom" />
        </AppBar>
    </common:LayoutAwarePage.BottomAppBar>

    <!--
        此网格用作定义以下两行的页的根面板:
        * 第 0 行包含后退按钮和页标题
        * 第 1 行包含页布局的其余部分
    -->
    <Grid Style="{StaticResource LayoutRootStyle}">
        <Grid.Background>
            <ImageBrush ImageSource="/Assets/background_default.png"/>
        </Grid.Background>
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <StackPanel x:Name="spLogo" Orientation="Horizontal" VerticalAlignment="Center" Margin="120,0,0,0" >
            <Image Source="Assets/logo_small.png" Width="250" Height="80" Margin="0"></Image>
        </StackPanel>
        <ProgressRing Width="80" Height="80" x:Name="pbLoading"   Grid.RowSpan="2" IsActive="True"></ProgressRing>
        <!-- 在大多数视图状态中使用的水平滚动网格-->
        <GridView
            x:Name="itemGridView"
            AutomationProperties.AutomationId="ItemGridView"
            AutomationProperties.Name="Grouped ArticleInfo"
            Grid.RowSpan="2"
            Padding="116,137,40,46"
            ItemsSource="{Binding Source={StaticResource cvs2}}"
            SelectionMode="None"
            IsItemClickEnabled="True"
            ItemClick="ItemsByLetterItemClick">
            <GridView.ItemsPanel>
                <ItemsPanelTemplate>
                    <VirtualizingStackPanel Orientation="Horizontal"/>
                </ItemsPanelTemplate>
            </GridView.ItemsPanel>
            <GridView.ItemTemplate>
                <DataTemplate>
                    <Grid HorizontalAlignment="Left" >
                        <StackPanel Orientation="Horizontal" Width="200" Margin="5,5,0,0">
                            <StackPanel Margin="0,0,0,0" Orientation="Vertical">
                                <TextBlock TextWrapping="Wrap" FontSize="18"  VerticalAlignment="Center" Text="{Binding articlename}" HorizontalAlignment="Left" FontFamily="Microsoft YaHei" />
                                <TextBlock TextWrapping="Wrap" FontSize="14"  Foreground="Green"  MaxHeight="20" VerticalAlignment="Center" Text="{Binding lastchapter}" FontFamily="Microsoft YaHei"  HorizontalAlignment="Left"/>
                            </StackPanel>
                        </StackPanel>
                    </Grid>
                </DataTemplate>
            </GridView.ItemTemplate>
            <GridView.GroupStyle>
                <GroupStyle>
                    <GroupStyle.HeaderTemplate>
                        <DataTemplate>
                            <Grid Margin="1,0,0,6">
                                <!--<Button
                                    AutomationProperties.Name="Group Title"
                                    Style="{StaticResource TextPrimaryButtonStyle}">-->
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Text="{Binding Key}" Margin="3,-7,10,10" Style="{StaticResource StyleGroupHeaderText}" />
                                    </StackPanel>
                                <!--</Button>-->
                            </Grid>
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>
                    <GroupStyle.Panel>
                        <ItemsPanelTemplate>
                            <VariableSizedWrapGrid Orientation="Vertical" Margin="0,0,80,0"/>
                        </ItemsPanelTemplate>
                    </GroupStyle.Panel>
                </GroupStyle>
            </GridView.GroupStyle>
        </GridView>
        <!-- 垂直滚动列表仅在对齐后使用-->
        <ListView
            x:Name="itemListView"
            AutomationProperties.AutomationId="ItemListView"
            AutomationProperties.Name="Grouped Items"
            Grid.Row="1"
            Visibility="Collapsed"
            Margin="0,-10,0,0"
            Padding="10,0,0,60"
            ItemsSource="{Binding Source={StaticResource cvs2}}"
            SelectionMode="None"
            IsSwipeEnabled="false"
            IsItemClickEnabled="True"
            ItemClick="ItemsByLetterItemClick">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <Grid HorizontalAlignment="Left" >
                        <StackPanel Orientation="Horizontal" Width="140" Margin="5,5,0,0">
                            <StackPanel Margin="0,0,0,0" Orientation="Vertical">
                                <TextBlock TextWrapping="Wrap" FontSize="18"  VerticalAlignment="Center" Text="{Binding articlename}" HorizontalAlignment="Left" FontFamily="Microsoft YaHei" />
                                <TextBlock TextWrapping="Wrap" FontSize="14"  Foreground="Green"  MaxHeight="20" VerticalAlignment="Center" Text="{Binding lastchapter}" HorizontalAlignment="Left" FontFamily="Microsoft YaHei" />
                            </StackPanel>
                        </StackPanel>
                    </Grid>
                </DataTemplate>
            </ListView.ItemTemplate>
            <ListView.GroupStyle>
                <GroupStyle>
                    <GroupStyle.HeaderTemplate>
                        <DataTemplate>
                            <Grid Margin="7,7,0,0">
                                <!--<Button
                                    AutomationProperties.Name="Group Title"
                                    Style="{StaticResource TextPrimaryButtonStyle}">-->
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Text="{Binding Key}" Margin="3,-7,10,10" Style="{StaticResource GroupHeaderTextStyle}" />
                                        <!--<TextBlock Text="{StaticResource ChevronGlyph}" FontFamily="Segoe UI Symbol" Margin="0,-7,0,10" Style="{StaticResource GroupHeaderTextStyle}"/>-->
                                    </StackPanel>
                                <!--</Button>-->
                            </Grid>
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>
                </GroupStyle>
            </ListView.GroupStyle>
        </ListView>

        <VisualStateManager.VisualStateGroups>

            <!-- 可视状态反映应用程序的视图状态-->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>

                <!-- 整页采用较窄的 100 像素页边距约定(纵向)-->
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <!--<ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>-->
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="navTop" Storyboard.TargetProperty="Margin">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="5,0,5,0"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemGridView" Storyboard.TargetProperty="Padding">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="96,137,10,56"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>

                <!--
                    对齐后，后退按钮和标题的样式将有所不同，并且在所有其他视图状态中显示的网格将
                    替换为列表表示形式
                -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="spLogo" Storyboard.TargetProperty="Margin">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="10,0,0,0"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="barNav" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemListView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemGridView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</common:LayoutAwarePage>
